package org.ithasu.tools;

import java.util.Collection;

public class CollectionTools {

	private CollectionTools() {
	}

	// -- Collections ----------------------------------------

	public static boolean isEmpty(Collection<?> col) {
		return col == null || col.isEmpty();
	}

	public static int size(Collection<?> col) {
		return col == null ? 0 : col.size();
	}

	public static <T> String toString(Collection<T> col) {
		StringBuffer buffer = null;
		for (T e : col) {
			if (buffer == null) {
				buffer = new StringBuffer(String.valueOf(e));
			} else {
				buffer.append(", ");
				buffer.append(String.valueOf(e));
			}
		}
		return buffer == null ? "" : buffer.toString();
	}

	// -- Arrays ----------------------------------------

	public static <T> boolean isEmpty(T[] array) {
		return array == null || array.length == 0;
	}

	public static <T> String toString(T[] array) {
		StringBuffer buffer = null;
		for (T e : array) {
			if (buffer == null) {
				buffer = new StringBuffer(String.valueOf(e));
			} else {
				buffer.append(", ");
				buffer.append(String.valueOf(e));
			}
		}
		return buffer == null ? "" : buffer.toString();
	}

}
